// 首页模块类型定义

// 消息接口
export interface Message {
  id: number
  from_uid: number
  to_uids: string
  title: string
  content: string
  file_ids: string
  is_draft: number
  send_time: number
  create_time: number
  update_time: number
  delete_time: number
  clear_time: number
  // 扩展字段
  from_name?: string
  read_user_names?: string
}

// 收件接口
export interface Msg {
  id: number
  message_id: number
  from_uid: number
  to_uid: number
  title: string
  content: string
  file_ids: string
  is_star: number
  read_time: number
  send_time: number
  create_time: number
  delete_time: number
  clear_time: number
  // 扩展字段
  from_name?: string
  sourse?: string
  types?: number
}

// 统计数据接口
export interface Statistics {
  msg_num: number
}

// 趋势数据接口
export interface TrendData {
  type: string
  value: number
}

// 概览统计数据项接口
export interface OverviewStatItem {
  name: string
  value: number
  color: string
  icon: string
  trend?: TrendData
}

// 财务统计数据项接口
export interface FinanceStatItem {
  name: string
  count: number
  amount_format: string
  color: string
  icon: string
}

// 合同金额统计数据项接口
export interface ContractAmountStat {
  name: string
  contract_type: string
  contract_count: number
  contract_amount: number
  contract_amount_format: string
  payment_amount: number
  payment_amount_format: string
  trend?: { type: string; value: number }
}

// 业务统计数据项接口
export interface BusinessStatItem {
  name: string
  value: string | number
  value_format?: string
  type: string
}

// 待办事项数据项接口
export interface PendingStatItem {
  name: string
  count: number
  num: number
  url: string
}

// 日程安排数据项接口
export interface ScheduleItem {
  id: number
  admin_id: number
  content: string
  start_time: number
  end_time: number
  start_time_format: string
  end_time_format: string
}

// 首页统计数据接口 (来自 types/home.ts)
export interface HomeStatistics {
  total: Array<OverviewStatItem>
  finance: Array<FinanceStatItem>
  business: Record<string, BusinessStatItem>
  todue: Array<PendingStatItem>
  schedule: Array<ScheduleItem>
  // 任务列表数据
  tasks: TaskData[]
  // 最新动态数据
  dynamics: Array<{
    id: number
    time: string
    content: string
  }>
}

// 首页统计数据接口 (来自 store/home.ts，与后端API返回结构匹配)
export interface StoreHomeStatistics {
  total: Array<{ name: string; num: number }>
  handle: Array<{ name: string; num: number; id: number; url: string }>
  todue: Array<{ name: string; num: number; id: number; url: string }>
  schedule: Array<{
    id: number
    admin_id: number
    content: string
    start_time: number
    end_time: number
    start_time_format: string
    end_time_format: string
  }>
  // 任务列表数据
  tasks: TaskData[]
  // 最新动态数据
  dynamics: Array<{
    id: number
    time: string
    content: string
  }>
}

// DashboardStatsService 返回数据结构
export interface DashboardStats {
  user_info: {
    id: number
    name: string
    username: string
    did: number
    position_id: number
    dept_name: string
    position_name: string
  }
  stats: {
    overview: OverviewStatItem[]
    finance: FinanceStatItem[]
    // 按日期区间统计的财务数据
    finance_by_period: {
      today: ContractAmountStat[]
      week: ContractAmountStat[]
      month: ContractAmountStat[]
      quarter: ContractAmountStat[]
    }
    business: {
      new_customers: BusinessStatItem
      new_contracts: BusinessStatItem
      contract_amount: BusinessStatItem
      contract_stats: {
        case_entrust: {
          name: string
          count: number
          amount: number
          average: number
          amount_format: string
          average_format: string
        }
        legal: {
          name: string
          count: number
          amount: number
          average: number
          amount_format: string
          average_format: string
        }
      }
      customer_stats: {
        company: {
          name: string
          total: number
          member: number
          non_member: number
        }
        individual: {
          name: string
          total: number
          member: number
          non_member: number
        }
      }
      lawcase_stage_stats: {
        total_count: number
        stages: Array<{
          stage: number
          stage_name: string
          count: number
        }>
      }
    }
    pending: Array<{
      type: string
      name: string
      count: number
      priority: string
      url: string
    }>
    schedule: {
      today: Array<{
        id: number
        admin_id: number
        content: string
        start_time: number
        end_time: number
        start_time_format: string
        end_time_format: string
        duration: number
        is_urgent: boolean
        status_text: string
      }>
      upcoming: any[]
      weekly: any[]
      statistics: {
        today_count: number
        upcoming_count: number
        week_total: number
        urgent_count: number
        month_total: number
      }
    }
    messages: {
      latest: any[]
      stats: {
        total: number
        unread: number
        read: number
      }
      unread_count: number
    }
    comprehensive: {
      week_completed_tasks?: {
        name: string
        value: number
        type: string
      }
      month_efficiency?: {
        name: string
        value: number
        unit: string
        type: string
      }
      dept_performance?: {
        name: string
        data: Array<{
          dept_name: string
          completed_tasks: number
        }>
        type: string
      }
    }
  }
  summary: {
    total_items: number
    pending_count: number
    unread_count: number
  }
  quick_actions: Array<{
    name: string
    icon: string
    url: string
    color: string
  }>
  permissions: {
    is_leader: boolean
    department_count: number
    can_approve: boolean
    permission_level: string
  }
  last_update: number
  last_update_format: string
}

// 任务数据接口
export interface TaskData {
  id: number
  name: string
  project_id: number
  project_name: string
  status: number
  priority: number
  create_time: string
  deadline: string
}

// 最新动态接口
export interface ActivityData {
  id: number
  time: string
  content: string
}

// 最新动态接口 (来自 store/home.ts)
export interface StoreActivityData {
  id: number
  user_name: string
  action: string
  target_name: string
  create_time: string
  target_type: string
}

// 快捷入口接口
export interface QuickAccessItem {
  id: number
  name: string
  icon: string
  url: string
}

// 任务优先级枚举
export enum TaskPriority {
  LOW = 1,
  MEDIUM = 2,
  HIGH = 3,
}

// 任务优先级标签映射
export const TaskPriorityMap = {
  [TaskPriority.LOW]: { label: '低', type: 'info' },
  [TaskPriority.MEDIUM]: { label: '中', type: 'warning' },
  [TaskPriority.HIGH]: { label: '高', type: 'danger' },
}

// 消息状态枚举
export enum MessageStatus {
  UNREAD = 0,
  READ = 1,
}

// 消息状态标签映射
export const MessageStatusMap = {
  [MessageStatus.UNREAD]: { label: '未读', type: 'danger' },
  [MessageStatus.READ]: { label: '已读', type: 'success' },
}

// 趋势类型枚举
export enum TrendType {
  UP = 'up',
  DOWN = 'down',
  STABLE = 'stable',
}

// 趋势类型标签映射
export const TrendTypeMap = {
  [TrendType.UP]: { label: '上升', type: 'success' },
  [TrendType.DOWN]: { label: '下降', type: 'danger' },
  [TrendType.STABLE]: { label: '稳定', type: 'info' },
}

// 消息模板接口
export interface Template {
  id: number
  title: string
  name: string
  msg_title: string
  msg_link: string
  msg_content: string
  admin_name?: string
  create_time: number
  status: number
}
